package main

import (
	"fmt"
	"github.com/gin-gonic/gin"
	"io"
	"math/rand"
	"os"
	"time"
)

func main() {

	rand.Seed(time.Now().UnixNano())

	gin.SetMode(gin.ReleaseMode)
	f, err := os.OpenFile("gin.log", os.O_APPEND|os.O_WRONLY|os.O_CREATE, os.ModeAppend)
	if err != nil {
		fmt.Println("err", err)
	}
	gin.DefaultWriter = io.MultiWriter(f)

	r := gin.Default()
	r.GET("/sleep0", func(c *gin.Context) {
		c.JSON(200, gin.H{
			"time": 0,
		})
	})
	r.GET("/sleep1", func(c *gin.Context) {
		time.Sleep(1 * time.Millisecond)
		c.JSON(200, gin.H{
			"time": 1,
		})
	})

	r.GET("/sleep5", func(c *gin.Context) {
		time.Sleep(5 * time.Millisecond)
		c.JSON(200, gin.H{
			"time": 5,
		})
	})

	r.GET("/sleep10", func(c *gin.Context) {
		time.Sleep(10 * time.Millisecond)
		c.JSON(200, gin.H{
			"time": 10,
		})
	})

	r.GET("/sleep50", func(c *gin.Context) {
		time.Sleep(50 * time.Millisecond)
		c.JSON(200, gin.H{
			"time": 50,
		})
	})

	r.GET("/sleep100", func(c *gin.Context) {
		time.Sleep(100 * time.Millisecond)
		c.JSON(200, gin.H{
			"time": 100,
		})
	})

	r.GET("/sleep200", func(c *gin.Context) {
		time.Sleep(200 * time.Millisecond)
		c.JSON(200, gin.H{
			"time": 200,
		})
	})

	r.Run()
}